# fake.explorer模块

from model.explorer import Explorer 
from error import Missing, Duplicate 



fakes = [
    Explorer(
        name='Claude Hande', 
        country='FR', 
        description='Scarce during full moons'
    ), 
    Explorer(
        name='Noah Weiser', 
        country='DE', 
        description='Myopic machete man'
    )
]

def find(name: str) -> Explorer | None: 
    for e in _explorers: 
        if e.name == name: 
            return e 
        return None 
    


def get_all() -> list[Explorer]: 
    return fakes; 



def get_one(name: str) -> Explorer | None: 
    for _explorer in fakes: 
        if _explorer.name == name: 
            return _explorer 
        

def create(explorer: Explorer) -> Explorer: 
    ex = find(explorer.name) 
    if ex: 
        raise Duplicate(f'explorer: {explorer.name} is duplicate error')
    
    _explorers.append(explorer) 
    return explorer 



# 更新部分信息
def modify(name: str, explorer: Explorer) -> Explorer: 
    e = find(name) 
    if e is None: 
        raise Missing('{name} missing error')
    return explorer 

# 替换
def replace(explorer: Explorer) -> Explorer: 

    return explorer 


def delete(name: str) -> None: 
    e = find(name) 
    if e is None: 
        raise Missing('{name} missing error') 
    _explorers.remove(e) 
    return None 


 

